package com.cjh.mybatis03.session.defaults;

import com.cjh.mybatis03.mapping.MappedStatement;
import com.cjh.mybatis03.session.Configuration;
import com.cjh.mybatis03.session.SqlSession;
import lombok.AllArgsConstructor;

/**
 * @Descripton
 * @Author cjh
 * @Date 2023/5/24 15:11
 */
@AllArgsConstructor
public class DefaultSqlSession implements SqlSession {
    /**
     * 映射器注册机
     */
    private Configuration configuration;

    @Override
    public <T> T selectOne(String statement) {
        return (T) ("你被代理了"+statement);
    }

    @Override
    public <T> T selectOne(String statement, Object parameter) {
        MappedStatement mappedStatement = configuration.getMappedStatement(statement);
        return (T) ("你被代理了！" + "\n方法：" + statement + "\n入参：" + parameter + "\n待执行SQL：" + mappedStatement.getSql());
    }

    @Override
    public Configuration getConfiguration() {
        return configuration;
    }

    @Override
    public <T> T getMapper(Class<T> type) {
        return configuration.getMapper(type, this) ;
    }
}
